﻿@model  AliMaMaModel
@{
    ViewBag.Title = "修改推广";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="path mb15">
    当前位置:<span>首页 &gt; </span><span>推广管理 &gt; </span><span>推广编辑</span>
</div>
@using (Html.BeginForm("Edit", "AliMaMa", FormMethod.Post))
{
    <div>
    <table class="tb-form">
        <tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>淘宝编号：
            </td>
            <td>
                @Html.TextBoxFor(x => x.ItemID, new { @class = "input-style-txt", @style = "width: 80px", @maxlength = "10" })
                @Html.ValidationMessageFor(x => x.ItemID)
            </td>
        </tr>
		<tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>价格：
            </td>
            <td>
                @Html.TextBoxFor(x => x.Price, new { @class = "input-style-txt", @style = "width: 80px", @maxlength = "10" })
                @Html.ValidationMessageFor(x => x.Price)
            </td>
        </tr>

		<tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>佣金：
            </td>
            <td>
                @Html.TextBoxFor(x => x.Commission, new { @class = "input-style-txt", @style = "width: 80px", @maxlength = "10" })
                @Html.ValidationMessageFor(x => x.Commission)
            </td>
        </tr>
        <tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>点击次数：
            </td>
            <td>
                @Html.TextBoxFor(x => x.Clicks, new { @class = "input-style-txt", @style = "width: 80px", @maxlength = "10" })
                @Html.ValidationMessageFor(x => x.Clicks)
            </td>
        </tr>
        
        <tr>
            <td class="tb-f-lable" style="width: 80px;">
                <span class="org">*</span>地址：
            </td>
            <td>
                @Html.TextBoxFor(x => x.TaoUrl, new { @class = "input-style-txt", @style = "width: 535px", @maxlength = "50" })
                @Html.ValidationMessageFor(x => x.TaoUrl)
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <input id="ProductID" name="ProductID" type="hidden"  value="@ViewData["ProductID"]"/>
			    @Html.HiddenFor(x => x.MMID);
                <input type="submit" value="保存" class="i-btn5" />
            </td>
        </tr>
    </table>
</div>
}
<script type="text/javascript">
    var editor;
    KindEditor.ready(function (K) {
        editor = K.create('#Description', {
            uploadJson: '/upload/Product',
            allowFileManager: false
        });
        K('input[name=save]').click(function (e) {

            $("#Description").val(editor.html());
            $("#GetForm").submit();
        });
    });


    function SetCity(id) {
        $.get("/Area/GetCity?id=" + id, function (data) {
            generateRegionSelect(data, "City", id);
        });
    }

    function SetCategoryFirst(id) {
        $.get('/Category/query_category_children?Pid=0',
    function (data) {
        generateSelect(data, "ddlCategoryFirst", id);
        SetCategorySecond(0);

    });
    }

    function SetCategorySecond(id) {
        var pid = $("#ddlCategoryFirst").val();
        $.get('/Category/query_category_children?Pid=' + pid,
    function (data) {
        generateSelect(data, "ddlCategorySecond", id);
        SetCategoryThird(0);
    });
    }

    function SetCategoryThird(id) {
        var pid = $("#ddlCategorySecond").val();
        $.get('/Category/query_category_children?Pid=' + pid,
    function (data) {
        generateSelect(data, "ddlCategoryThird", id);
    });
    }

    function SetCategoryVal() {
        var cid = $("#ddlCategoryThird").val();
        $("#CategoryID").val(cid);

    }
    function SetAreaVal() {
        var aid = $("#City").val();
        $("#AreaID").val(aid);
    }

    /*** 生成类目中的内容*/
    function generateSelect(data, ulId, selId) {
        $("#" + ulId).empty();
        // 如果结果为成功
        var resData = data;
        for (var i = 0; i < resData.length; i++) {

            $("#" + ulId)[0].options.add(new Option(resData[i].CategoryName, resData[i].CategoryID));
        }
        if (selId > 0) {
            $("#" + ulId).attr("value", '' + selId + '');
        } else {
            $("#" + ulId)[0].selectedIndex = 0;
        }

    }

    function generateRegionSelect(data, ulId, selId) {
        $("#" + ulId).empty();
        for (var i = 0; i < data.length; i++) {

            $("#" + ulId)[0].options.add(new Option(data[i].AreaName, data[i].AreaID));

        }
        if (selId > 0) {
            $("#" + ulId).attr("value", '' + selId + '');
        } else {
            $("#" + ulId)[0].selectedIndex = 0;
        }

    }
</script>
